package com.ys.controller;

import com.github.pagehelper.PageHelper;
import com.ys.mapper.DrugsMapper;
import com.ys.pojo.Drugs;
import com.ys.pojo.Order;
import com.ys.vo.PageVo;
import com.ys.vo.ResultVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class TongJiContorller {

    @Resource
    private DrugsMapper drugsMapper;


    @RequestMapping("/kuCuiTongJi")
    @ResponseBody
    public ResultVo kuCuiTongJi(){
        ResultVo resultVo = new ResultVo();
        resultVo.setObj(new PageVo(drugsMapper.kucuntongji()));
        return resultVo;
    }
    @RequestMapping("/PaiHangTongJi")
    @ResponseBody
    public ResultVo PaiHangTongJi(){
        ResultVo resultVo = new ResultVo();
        resultVo.setObj(drugsMapper.panHnag());
        return resultVo;
    }


    @RequestMapping("/ShouRuTongJi")
    @ResponseBody
    public ResultVo ShouRuTongJi(){
        ResultVo resultVo = new ResultVo();
        List list = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String today=sdf.format(new Date());
        String nian = today.substring(0,4);
        String yue = today.substring(today.indexOf("-")+1,today.lastIndexOf("-"));
        Integer nian1 = 0;
        Integer yue1 =0;
        //当前月份=01的时候，月份就等于2018-12
        if(yue=="01"){
            nian1 = Integer.parseInt(nian)-1;

            yue1 = 12;
        }else{
            nian1 = Integer.parseInt(nian);
            yue1 = Integer.parseInt(yue)-1;
        }
        List<Order> list1 = drugsMapper.shouRu1(nian,yue);
        List<Order> list2 = drugsMapper.shouRu1(String.valueOf(nian1),String.valueOf(yue1));
        list.add(list1);
        list.add(list2);
        resultVo.setObj(list);
        return resultVo;
    }

}
